﻿using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.ReadApi.Command.Raddit.BW;
using U.B.Repistory;

namespace U.B.ReadApi.CommandHander.Raddit.BWHA
{
    public class GetproductCommandHander : IRequestHandler<GetproductCommand, ApiResult<Product>>
    {
        public IRepistory<Product> ProductRepistory;

        public GetproductCommandHander(IRepistory<Product> productRepistory)
        {
            ProductRepistory = productRepistory;
        }
        public Task<ApiResult<Product>> Handle(GetproductCommand request, CancellationToken cancellationToken)
        {
            ApiResult<Product> apiResult=new ApiResult<Product>();
            var result = ProductRepistory.GetAll().FirstOrDefault(x=>x.ProductId==request.ProductId);
            apiResult.code = Renum.显示成功;
            apiResult.Message=Renum.显示成功.ToString();
            apiResult.Data = result;
            return Task.FromResult(apiResult);
        }
    }
}
